<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>

<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            考试班级：
                            <select required name="classId">
                                <option value="">全部</option>
                                <c:forEach items="${classes}" var="classs">
                                    <option value="${classs.id}">${classs.name}</option>
                                </c:forEach>
                            </select>
                        </li>
                        <li>
                            试卷名称：<input type="text" name="testPaperName" value=""/>
                        </li>
                        <li class="select-time">
                            <label>开考时间： </label>
                            <input type="text" class="time-input" id="startExamTime" placeholder="开始时间"
                                   name="startExamTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endExamTime" placeholder="结束时间"
                                   name="endExamTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true">

            </table>
        </div>
    </div>
</div>
<%@include file="../../common/include-footer.jsp" %>
<script th:inline="javascript">
    var prefix = "/exam";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/update/{id}",
            removeUrl: prefix + "/remove/{id}",
            sortName: "asc",
            height: 500,
            modalName: "考试",
            columns: [
                {
                    field: 'id',
                    title: '考试编号'
                },
                {
                    field: 'title',
                    title: '考试名'
                },
                {
                    field: 'classes',
                    title: '考试班级',
                    formatter:function(val, item, rowIndex){
                        var names = [];
                        for (var i = 0; i < val.length; i++){
                            names.push(val[i].name);
                        }
                        return names.join('-');
                    }
                },
                {
                    field: 'testPaper.name',
                    title: '试卷名'
                },
                {
                    field: 'examTime',
                    title: '开考时间',
                    formatter:function(val, item, rowIndex){
                        var date = new Date(val);
                        var YY = date.getFullYear() + '-';
                        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                        var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                        var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                        var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                        return YY + MM + DD +" "+hh + mm + ss;
                    }
                }]
        };
        $.table.init(options);

        $('select[name=classId]').change(function () {
            var classId = $(this).val();
            $.ajax({
                url:"${pageContext.request.contextPath}/examResult/getExamNameByClassId",    //请求的url地址
                dataType:"json",   //返回格式为json
                data:{"classId":classId},    //参数值
                type:"POST",   //请求方式
                success:function(data){
                    $('.examC').remove();
                    var exams = data;
                    for(var i=0;i<exams.length;i++){
                        var examId = exams[i].id;
                        var title =exams[i].title;
                        // $("#subid").val([subid,subname]);
                        //给下拉框动态赋值
                        $("select[name=examId]").append("<option value='"+examId+"' class='examC'>"+title+"</option>");
                    }
                    // alert($("#subid").val());
                }

            });
            $('select[name=examId]').attr("disabled",false);
        });

    });
</script>
</body>
</html>
